package com.watcloud.plugin.impl.postgresql;

import com.alibaba.nacos.plugin.datasource.constants.TableConstant;
import com.alibaba.nacos.plugin.datasource.mapper.HistoryConfigInfoMapper;
import com.watcloud.plugin.constants.DataSourceConstant;

public class HistoryConfigInfoMapperByPostgresql extends PostgresqlAbstractMapper implements HistoryConfigInfoMapper {

	@Override
	public String removeConfigHistory() {
		return "DELETE FROM his_config_info WHERE gmt_modified < ? LIMIT ?";
	}

	@Override
	public String pageFindConfigHistoryFetchRows(int pageNo, int pageSize) {
		final int offset = (pageNo - 1) * pageSize;
		final int limit = pageSize;
		return  "SELECT nid,data_id,group_id,tenant_id,app_name,src_ip,src_user,op_type,gmt_create,gmt_modified FROM his_config_info "
				+ "WHERE data_id = ? AND group_id = ? AND tenant_id = ? ORDER BY nid DESC  LIMIT " + limit + " offset " + offset;
	}

	@Override
	public String getTableName() {
		return TableConstant.HIS_CONFIG_INFO;
	}

	@Override
	public String getDataSource() {
		return DataSourceConstant.POSTGRESQL;
	}

}
